function CheckUtils() {
};

CheckUtils.addToArray = function(array, inputElm, checkFunc, errorArr) {
  array[array.length] = { inputElm: inputElm, checkFunc: checkFunc, errorArr: errorArr };
  if (array.length == 1) {
    CheckUtils.next(array);
  }
};

CheckUtils.next = function(array) {
  if (array.length == 0) {
    return;
  }
  var func = function() { 
    array.splice(0, 1);
    CheckUtils.next(array);
  };
  var item = array[0];
  CheckUtils.removeErrors(item.inputElm, item.errorArr);
  item.checkFunc(item.inputElm, func, item.errorArr);
};

CheckUtils.removeErrors = function(inputElm, errorArr) {
  inputElm.style.color = '';
  inputElm.style.backgroundColor = '';
  for (var idx in errorArr) {
    var obj = errorArr[idx];
    if (obj.id == inputElm.id) {
      while (inputElm.parentNode.childNodes.length > 1) {
        inputElm.parentNode.removeChild(inputElm.parentNode.childNodes[1]);
      }
      errorArr.splice(idx, 1);
    }
  }
};

CheckUtils.addError = function(inputElm, errorArr, message) {
  var div = document.createElement('div');
  div.style.fontSize = '11px';
  div.style.color = '#ff0000';
  div.style.fontWeight = 'bold';
  div.style.padding = '0 0 3px 5px';
  inputElm.style.color = '#fff';
  inputElm.style.backgroundColor = '#ff0000';
  div.appendChild(document.createTextNode(message));
  inputElm.parentNode.appendChild(div);
  errorArr[errorArr.length] = inputElm;
};

CheckUtils.valEmail = function(value) {
  var re = /^[a-zA-Z0-9]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}$/;
  if (value == null || value == '') {
    return false;
  } else if (!re.test(value)) {
    return false;
  }
  return true;
};

CheckUtils.valDate = function(value) {
  var regExp = /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1]))$/;
  if (value == null || value == '') {
    return false;
  } else if (!regExp.test(value)) {
    return false;
  }
  return true;
};
